package com.example.workspace.utils;


import com.example.workspace.dto.PositionDto;

import java.awt.*;
import java.awt.event.InputEvent;
import java.net.URL;
import java.util.List;
import java.util.Random;

public class ToolUtils {


    public static void main(String[] args) {
        getPointInfo();
    }


    public static void loadOpencv(){
        URL url = ClassLoader.getSystemResource("opencv_java481.dll");
        System.load(url.getPath());
    }

    /**
     * 手动获取坐标
     */
    public static void getPointInfo(){
        int x = 0;
        int y = 0;
        while(true){
            PointerInfo pinfo = MouseInfo.getPointerInfo();
            int mx = pinfo.getLocation().x;
            int my = pinfo.getLocation().y;
            if (x!=mx||y!=my){
                x=mx;
                y=my;
                System.out.println("x:"+mx+",y:"+my);
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                System.out.println(e.getMessage());
            }
        }
    }

    /**
     * 安全的按键,随机延迟,传入多个键
     */
    public static void keyPress(Robot robot,int... key){


        Random random = new Random();

        for (int i : key) {
            int nextInt = random.nextInt(4);

            robot.keyPress(i);
            robot.delay(1000);
            robot.keyRelease(i);
            robot.delay(nextInt * 1000);

        }

    }


}
